/**
 * Project Name:九色鹿
 * File Name:VerificationSmsServiceImpl.java
 * Package Name:com.fxp.project.sms.chuanglan.service.impl
 * Date:2021年09月13日 17:29
 * Copyright (c) 2021, Jason.Wang All Rights Reserved.
 */
package com.fxp.project.sms.chuanglan.service.impl;

import com.fxp.project.jiuselu.commons.exceptions.JiuLuException;
import com.fxp.project.sms.chuanglan.provider.VerifySmsProvider;
import com.fxp.project.sms.chuanglan.service.ISmsService;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * ClassName:VerificationSmsServiceImpl<br/>
 * Function: 验证码短信实现<br/>
 * Date:2021年09月13日 17:29<br/>
 *
 * @author Jason.Wang
 * @version 1.0.0.0
 * @see
 * @since JDK 8
 */
@Data
@Log4j2
@Component
public class VerificationSmsServiceImpl implements ISmsService {

    private final VerifySmsProvider provider;

    private volatile static VerificationSmsServiceImpl instance;

    /**
     * initInstance: 获取单例的实体对象<br/>
     *
     * @param provider
     * @author Jason.Wang
     * @date 2021/9/13 17:45
     */
    public static void initInstance(VerifySmsProvider provider) {
        if (instance == null) {
            synchronized (VerificationSmsServiceImpl.class) {
                if (instance == null) {
                    instance = new VerificationSmsServiceImpl(provider);
                }
            }
        }
    }

    /**
     * getInstance: 获取单例对象方法<br/>
     *
     * @return
     * @author Jason.Wang
     * @date 2021/9/13 17:46
     */
    public static VerificationSmsServiceImpl getInstance() {
        return instance;
    }

    /**
     * VerificationSmsServiceImpl: 私有构建方法<br/>
     *
     * @param provider
     * @author Jason.Wang
     * @date 2021/9/13 17:46
     */
    private VerificationSmsServiceImpl(VerifySmsProvider provider) {
        this.provider = provider;
    }

    /**
     * sendSms: 统一发送短息的接口<br/>
     *
     * @param mobile
     * @param message
     * @return
     * @throws RuntimeException
     * @author Jason.Wang
     * @createTime 2020/4/1 22:07
     */
    @Override
    public boolean sendSms(String mobile, String message) throws JiuLuException {
        return provider.sendSms(mobile, message);
    }
}